﻿namespace m2land.RedRuler
{
    using System;
    using System.Globalization;
    using System.Windows.Forms;

    public partial class InfoPanel : Form
    {
        internal RedRuler RedRulerForm { get; set; }

        public InfoPanel()
        {
            this.InitializeComponent();
            this.KeyPreview = true;
            this.KeyPress += this.OnKeyPress;

            this.FormClosing += this.OnFormClosing;
        }

        private void OnFormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true; // this cancels the close event.
        }

        private void OnKeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
                case (char)13:
                    this.SetRedRulerDimension();
                    break;
                default:
                    break;
            }
        }

        private void buttonSetDimension_Click(object sender, EventArgs e)
        {
            this.SetRedRulerDimension();
        }

        private void SetRedRulerDimension()
        {
            this.RedRulerForm.Height = int.Parse(this.numericUpDownHeight.Value.ToString(CultureInfo.InvariantCulture));
            this.RedRulerForm.Width = int.Parse(this.numericUpDownWidth.Value.ToString(CultureInfo.InvariantCulture));
        }

        private void InfoPanel_Load(object sender, EventArgs e)
        {

        }

        private void numericUpDownWidth_ValueChanged(object sender, EventArgs e)
        {

        }
    }
}